Array.prototype.myReduce = function(cb, initial) {
    if (typeof cb !== 'function') {
        throw new TypeError('cb must be a function')
    }
    const array = this
    let pre = initial || array[0]
    for (let index = initial ? 0 : 1; index < array.length; index++) {
        pre = cb(pre, array[index], index, array)
    }
    return pre
}